//
//  CYAccountCell.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/8/14.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYAccountCell.h"

@interface CYAccountCell()
@property (nonatomic, strong) CYLabel *moneyLBL;
@property (nonatomic, strong) CYLabel *stateLBL;
@end
@implementation CYAccountCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setSeparatorInset:UIEdgeInsetsZero];
        [self setLayoutMargins:UIEdgeInsetsZero];
    }
    
    return self;
}

- (CYLabel *)moneyLBL{
    if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:_money size:AL(PT(30)) textcolor:ColorHex(0xff5b05)];
        [self addSubview:_moneyLBL];
        
        WS(self)
        [_moneyLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.mas_right).with.offset(-AL(PT(30)));
            make.centerY.equalTo(weakSelf);
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

- (CYLabel*)stateLBL{
    if (!_stateLBL) {
        _stateLBL = [[CYLabel alloc]initWithText:_state size:AL(PT(26)) textcolor:[UIColor blackColor]];
        [self addSubview:_stateLBL];
        
        [_stateLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.detailTextLabel.mas_right).with.offset(AL(PT(30)));
            make.centerY.equalTo(self.detailTextLabel);
            make.size.mas_equalTo(_stateLBL.bounds.size);
        }];
    }
    return _stateLBL;
}

- (void)setMoney:(NSString *)money{
    if (_money != money)
        _money = money;
    if ([_money isEqualToString:@"0"])
        self.moneyLBL.text = @"未处理";
    else if ([_money isEqualToString:@"1"])
        self.moneyLBL.text = @"处理中";
    else if ([_money isEqualToString:@"2"])
        self.moneyLBL.text = @"提现成功";
    else if ([_money isEqualToString:@"3"])
        self.moneyLBL.text = @"提现失败";
    else if ([_money isEqualToString:@"4"])
        self.moneyLBL.text = @"已过期";
    else
        self.moneyLBL.text = _money;
    [self updateMoneyLBLColorAndLayout];
}

/** 0 未处理
 *  1 处理中
 *  2 充值成功
 *  3 充值失败
 *  4 已过期
 */
- (void)setState:(NSString *)state{
    if (_state != state)
        _state = state;
    if ([_state isEqualToString:@"0"])
        self.stateLBL.text = @"未处理";
    else if ([_state isEqualToString:@"1"])
        self.stateLBL.text = @"处理中";
    else if ([_state isEqualToString:@"2"])
        self.stateLBL.text = @"充值成功";
    else if ([_state isEqualToString:@"3"])
        self.stateLBL.text = @"充值失败";
    else if ([_state isEqualToString:@"4"])
        self.stateLBL.text = @"已过期";
    [self setupStateLBLColorAndLayout];
    
}
- (void)setTitle:(NSString *)title{
    if (_title != title)
        _title = title;
    self.textLabel.text = title;
    self.textLabel.font = [UIFont systemFontOfSize:AL(PT(30))];
    self.textLabel.textColor = ColorHex(0x333333);
}

- (void)setDetailTitle:(NSString *)detailTitle{
    if (_detailTitle != detailTitle)
        _detailTitle = detailTitle;
    self.detailTextLabel.text = detailTitle;
    self.detailTextLabel.font = [UIFont systemFontOfSize:AL(PT(22))];
    self.detailTextLabel.textColor = ColorHex(0x888888);
    
}

/** 0 未处理
 *  1 处理中
 *  2 充值成功
 *  3 充值失败
 *  4 已过期
 */
- (void)setupStateLBLColorAndLayout{
    if ([_state isEqualToString:@"充值中"] || [_state isEqualToString:@"1"])
        _stateLBL.textColor = ColorHex(0xff803d);
    else if ([_state isEqualToString:@"0"])
        _stateLBL.textColor = ColorHex(0x888888);
    else if ([_state isEqualToString:@"2"] || [_state isEqualToString:@"已成功"] )
        _stateLBL.textColor = RGBA(66, 204, 92, 1);
    else if ([_state isEqualToString:@"3"] || [_state isEqualToString:@"未成功"])
        _stateLBL.textColor = THEME_COLOR;
    //bounds
    [_stateLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_stateLBL.bounds.size);
    }];
}

- (void)updateMoneyLBLColorAndLayout{
    
    if ([_money isEqualToString:@"处理中"])
        _moneyLBL.textColor = ColorHex(0xff803d);
    else if ([_money isEqualToString:@"未处理"])
        _moneyLBL.textColor = ColorHex(0x888888);
    else if ([_money isEqualToString:@"提现成功"])
        _moneyLBL.textColor = RGBA(66, 204, 92, 1);
    else if ([_money isEqualToString:@"提现失败"])
        _moneyLBL.textColor = THEME_COLOR;
    //bounds
    [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_moneyLBL.bounds.size);
    }];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end

